package model;
import java.util.AbstractSet;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Set;


public class StudentSet extends AbstractSet<Student>{
	
	  private ArrayList<Student> list;

	  public StudentSet() {
	    list = new ArrayList<Student>();
	  }

	  public StudentSet(Collection<Student> col) {
	    list = new ArrayList<Student>();

	    // No need to check for dups if col is a set
	    Iterator<Student> itor = col.iterator();
	    if (col instanceof Set) {
	      while (itor.hasNext()) {
	        list.add(itor.next());
	      }
	    } else {
	      while (itor.hasNext()) {
	        add(itor.next());
	      }
	    }
	  }

	  public Iterator<Student> iterator() {
	    return list.iterator();
	  }

	  public int size() {
	    return list.size();
	  }

	  public boolean add(Student element) {
	    boolean modified;
	    if (modified = !list.contains(element)) {
	      list.add(element);
	    }
	    return modified;
	  }

	  public boolean remove(Object element) {
	    return list.remove(element);
	  }

	  public boolean isEmpty() {
	    return list.isEmpty();
	  }

	  public boolean contains(Object element) {
	    return list.contains(element);
	  }

	  public void clear() {
	    list.clear();
	  }

	  @SuppressWarnings("unchecked")
	public Object clone() {
	    try {
	      StudentSet newSet = (StudentSet) super.clone();
	      newSet.list = (ArrayList<Student>) list.clone();
	      return newSet;
	    } catch (CloneNotSupportedException e) {
	      throw new InternalError();
	    }
	  }

}
